package com.appwoo.txtws.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.appwoo.android.activity.BaseActivity;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.component.DBHelper;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.MD5Builder;
import com.appwoo.txtws.component.RqSP;
import com.appwoo.txtws.service.RQBindInfo;
import com.appwoo.txtws.service.RQKeepAlive;

public class BindActivity extends BaseActivity
  implements View.OnClickListener
{
  private String alertString;
  private Button btn_bind_no;
  private Button btn_bind_yes;
  private Bundle bundle;
  private Context context;
  private SharedPreferences.Editor editor;
  private EditText et_bind_oldpwd;
  private SharedPreferences sp;
  private TextView tv_bind_newuser;
  private TextView tv_bind_olduser;
  private ProgressDialog v_progressDialog;

  private void addListener()
  {
    this.btn_bind_yes.setOnClickListener(this);
    this.btn_bind_no.setOnClickListener(this);
  }

  private String bgAddBind()
  {
    if (this.bundle == null)
      this.bundle = getIntent().getExtras();
    StateBean localStateBean = new RQBindInfo().addBind(this.context, this.bundle.getString("account"));
    if (localStateBean != null)
      if (localStateBean.getCode().equals("0"))
        this.alertString = getString(2131427574);
    try
    {
      String str2 = this.bundle.getString("account");
      new DBHelper(this.context).updateLogin(str2, MD5Builder.getMD5("txtw"), "1", str2, Global.getIMEI(this.context), null);
      label113: RqSP localRqSP = new RqSP();
      String str1 = this.bundle.getString("account");
      Global.USERNAME = str1;
      Global.PARENT_ID = str1;
      localRqSP.setParentId(str1, this.context);
      localRqSP.setChildId(str1, this.context);
      Global.PASSWORD = MD5Builder.getMD5("txtw");
      while (true)
      {
        return this.alertString;
        this.alertString = localStateBean.getDesc();
        continue;
        this.alertString = getString(2131427515);
      }
    }
    catch (Exception localException)
    {
      break label113;
    }
  }

  private void init()
  {
    this.sp = getSharedPreferences("user_info", 0);
    this.editor = this.sp.edit();
    this.btn_bind_yes = ((Button)findViewById(2131492902));
    this.btn_bind_no = ((Button)findViewById(2131492903));
    this.tv_bind_olduser = ((TextView)findViewById(2131492899));
    this.tv_bind_newuser = ((TextView)findViewById(2131492901));
    this.et_bind_oldpwd = ((EditText)findViewById(2131492900));
    this.bundle = getIntent().getExtras();
    this.tv_bind_newuser.setText(this.bundle.getString("account"));
    if (Global.isBinded == 1)
    {
      if (Global.PARENT_ID != null)
      {
        if (Global.PARENT_ID.equals(""))
        {
          this.tv_bind_olduser.setText(Global.USERNAME);
          return;
        }
        this.tv_bind_olduser.setText(Global.PARENT_ID);
        return;
      }
      this.tv_bind_olduser.setText(Global.USERNAME);
      return;
    }
    this.tv_bind_olduser.setText(getString(2131427572));
    this.et_bind_oldpwd.setVisibility(4);
  }

  private void yesBtn()
  {
    String str1 = Global.PASSWORD;
    String str2 = this.et_bind_oldpwd.getText().toString();
    String str3 = this.tv_bind_olduser.getText().toString();
    if (Global.isSchool == 1)
    {
      alertMessage(getString(2131427573));
      finish();
      return;
    }
    if (str3.equals(getString(2131427572)))
    {
      new BindAsyncTask().execute(new String[] { "addBind" });
      return;
    }
    if (str2.equals(""))
    {
      alertMessage(getString(2131427575));
      return;
    }
    if (MD5Builder.getMD5(str2).equals(str1))
    {
      new BindAsyncTask().execute(new String[] { "addBind" });
      return;
    }
    alertMessage(getString(2131427576));
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
      return;
    case 2131492902:
      yesBtn();
      return;
    case 2131492903:
    }
    finish();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903046);
    init();
    addListener();
  }

  public class BindAsyncTask extends AsyncTask<String, Integer, String>
  {
    private String method = "";

    public BindAsyncTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      this.method = paramArrayOfString[0];
      if (this.method.equals("addBind"))
        return BindActivity.this.bgAddBind();
      if (this.method.equals("keepalive"))
        RQKeepAlive.getInstance().call(BindActivity.this);
      return "";
    }

    protected void onPostExecute(String paramString)
    {
      if (this.method.equals("addBind"))
      {
        BindActivity.this.alertMessage(BindActivity.this.alertString);
        if (BindActivity.this.editor == null)
          BindActivity.this.editor = BindActivity.this.sp.edit();
        if (BindActivity.this.getString(2131427574).equals(BindActivity.this.alertString))
        {
          String str1 = BindActivity.this.bundle.getString("account");
          String str2 = BindActivity.this.bundle.getString("account");
          Global.USERNAME = str1;
          Global.PARENT_ID = str2;
          BindActivity.this.editor.putBoolean("isBind", true);
          BindActivity.this.editor.putString("account", str1);
          BindActivity.this.editor.putString("pid", str2);
          BindActivity.this.editor.commit();
          SharedPreferences.Editor localEditor = BindActivity.this.getSharedPreferences("sys", 0).edit();
          localEditor.putInt("isfirst", 1);
          localEditor.putInt("isupload", 0);
          localEditor.commit();
          new BindAsyncTask(BindActivity.this).execute(new String[] { "keepalive" });
        }
        BindActivity.this.alertMessage(BindActivity.this.alertString);
        BindActivity.this.finish();
      }
      try
      {
        BindActivity.this.v_progressDialog.dismiss();
        return;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
    }

    protected void onPreExecute()
    {
      if ((BindActivity.this.v_progressDialog == null) || (!BindActivity.this.v_progressDialog.isShowing()))
      {
        if (BindActivity.this.context == null)
          BindActivity.this.context = BindActivity.this;
        BindActivity.this.v_progressDialog = new ProgressDialog(BindActivity.this.context);
        BindActivity.this.v_progressDialog.setMessage(BindActivity.this.getString(2131427516));
        BindActivity.this.v_progressDialog.setCancelable(true);
        BindActivity.this.v_progressDialog.show();
      }
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.BindActivity
 * JD-Core Version:    0.6.2
 */